package cn.lyd.base.until;

import lombok.Data;

/**
 * 工具类：封装增删改的返回结果
 */
@Data
public class AjaxResult {
    private Boolean success = true;
    private String msg = "操作成功";

    //上传接口需要返回是否成功信息以及图片路径
    //方便以后扩展 - 返回任意数据类型都有用,用来封装额外的返回参数
    private Object resultObj;

    public AjaxResult(){}
    public AjaxResult(Boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

    public static AjaxResult me(){
        return new AjaxResult();
    }

    public AjaxResult success(){
        return me().setSuccess(true).setMsg("操作成功！");
    }
    public AjaxResult success(Object resultObj){
        return me().setSuccess(true).setMsg("操作成功！").setResultObj(resultObj);
    }


    public AjaxResult fail(String msg){
        return me().setSuccess(false).setMsg(msg);
    }

    public AjaxResult fail(){
        return me().setSuccess(false).setMsg("操作失败！");
    }



    public Boolean getSuccess() {
        return success;
    }

    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public AjaxResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Object getResultObj() {
        return resultObj;
    }

    public AjaxResult setResultObj(Object resultObj) {
        this.resultObj = resultObj;
        return this;
    }


    public static void main(String[] args) {
        System.out.println(new AjaxResult());
        System.out.println(AjaxResult.me());
        System.out.println(new AjaxResult(false,"删除失败"));
        System.out.println(AjaxResult.me().setSuccess(false).setMsg("删除失败"));
    }
}
